package com.deft.design.observer;

import com.deft.design.observer.event.EventManager;
import com.deft.design.observer.event.listener.EventListener;
import com.deft.design.observer.event.listener.MessageEventListener;
import com.deft.design.observer.event.listener.MqEventListener;

/**
 * @author Hide丶love
 * @date 2022/05/18
 **/
public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.MESSAGE);
        eventManager.subscribe(EventManager.EventType.MQ, new MqEventListener());
        eventManager.subscribe(EventManager.EventType.MESSAGE, new MessageEventListener());
    }

    public LotteryResult draw(String uId) {
        LotteryResult result = doDraw(uId);
        eventManager.notify(EventManager.EventType.MQ, result);
        eventManager.notify(EventManager.EventType.MESSAGE, result);
        return result;
    }

    protected abstract LotteryResult doDraw(String uId);
}
